package com.day240701.controller;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AddCookieServlet", value = "/addCookie")
public class AddCookieServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 怎么将数据 保存到 浏览器的 cookies 中
        Cookie c1 = new Cookie("username", "wwy");
        c1.setMaxAge(7*24*60*60); // 保存7天 单位是秒

        Cookie c2 = new Cookie("password", "123");
        c2.setMaxAge(7*24*60*60);

        response.addCookie(c1);
        response.addCookie(c2);

    }
}
